package guowei.guliuser.user.service.impl;

import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import guowei.common.utils.PageUtils;
import guowei.common.utils.Query;

import guowei.guliuser.user.dao.MemberLevelDao;
import guowei.guliuser.user.entity.MemberLevelEntity;
import guowei.guliuser.user.service.MemberLevelService;


@Service("memberLevelService")
public class MemberLevelServiceImpl extends ServiceImpl<MemberLevelDao, MemberLevelEntity> implements MemberLevelService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<MemberLevelEntity> page = this.page(
                new Query<MemberLevelEntity>().getPage(params),
                new QueryWrapper<MemberLevelEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 可以根据key搜索值
     * @param params
     * @return
     */
    @Override
    public PageUtils selectByKeys(Map<String, Object> params) {
        String key = (String) params.get("key");
        IPage<MemberLevelEntity> page = null;
        if(key == null){
            page = this.page(
                    new Query<MemberLevelEntity>().getPage(params),
                    new QueryWrapper<MemberLevelEntity>()
            );
        }else {
            QueryWrapper<MemberLevelEntity> wrapper = new QueryWrapper<>();
            wrapper.eq("id",key).or().like("name",key).or().eq("growth_point",key)
                    .or().eq("free_freight_point",key).or().eq("comment_growth_point",key)
                    .or().like("note",key);
             page = this.page(new Query<MemberLevelEntity>().getPage(params),
                    wrapper);
        }
        return new PageUtils(page);
    }

    /**
     * 得到默认等级
     */
    @Override
    public Long getDefaultLevel() {
        MemberLevelEntity one = this.getOne(new QueryWrapper<MemberLevelEntity>().eq("default_status", 1));
        Long id = one.getId();
        return id;
    }

    @Override
    public PageUtils getMembersLevel(Map<String, Object> params) {
        IPage<MemberLevelEntity> page = this.page(new Query<MemberLevelEntity>().getPage(params),
                new QueryWrapper<MemberLevelEntity>());
        return new PageUtils(page);
    }



}